package com.fly.server.vo;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * @ClassName Result
 * @Description TODO
 * @Author Fly
 * @Version
 * @Date 2019-12-26 0026 10:19
 */
@Data
public class Result<T> implements Serializable {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * msg
     */
    private String msg;
    /**
     * 数据
     */
    private T date;

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.date = data;
    }

    public Result() {
    }

    public static <T> Result<T> ok(String msg, T data) {
        return new Result<T>(HttpStatus.OK.value(), msg, data);
    }

    public static <T> Result<T> ok() {
        return new Result<T>(HttpStatus.OK.value(), "request success!", null);
    }

    public static <T> Result<T> ok(T data) {
        return ok("request success!", data);
    }

    public static <T> Result<T> fail(String msg, T data) {
        return new Result<T>(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg, data);
    }

    public static <T> Result<T> fail(String msg) {
        return fail(msg, null);
    }
}
